package moderation;

import javax.ejb.Stateless;

@Stateless
public class ModerationImpl implements Moderation {

	private String[] list = { "putain", "wtf" };

	@Override
	public String messageModerate(String msg) {
		
		String modifiedMessage = new String(msg);
		modifiedMessage = modifiedMessage.substring(0, modifiedMessage.length()-1);
		String messageCopy = new String(modifiedMessage);
		
		String replacement;
		for (String str : list) {
			replacement = "";

			
			for (int i = 0; i < str.length(); i++) {
				replacement += "*";
			}
			modifiedMessage = modifiedMessage.replaceAll(str, replacement);
		}
		if (!modifiedMessage.equals(messageCopy)) {
			modifiedMessage += " [auto-moderated]";
		}
		return modifiedMessage;

	}

}
